<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"
          name="viewport"/>
    <title>后台登录</title>
    <link href="../../static/admin/layui/css/layui.css" rel="stylesheet" type="text/css"/>
    <link href="../../static/admin/css/login.css" rel="stylesheet" type="text/css"/>

</head>

<body>
<div id="box">
    <div class="m-login">
        <img height="120" src="../../static/public/images/logo2.png"
             width="380"/>
        <div class="m-login-warp" style="background-color: rgba(255,255,255,0.19)">
            <form class="layui-form">
                <div class="layui-form-item">
                    <input autocomplete="off" class="layui-input" id="username" lay-verify="required" name="username"
                           placeholder="用户名"
                           required type="text">
                </div>
                <div class="layui-form-item">
                    <input autocomplete="off" class="layui-input" id="password" lay-verify="required" name="password"
                           placeholder="密码"
                           required type="password">
                </div>

                <div class="layui-form-item m-login-btn">
                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-normal" lay-filter="login" lay-submit>登录</button>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-primary" type="reset">返回</button>
                    </div>
                </div>
            </form>
        </div>
        <p class="copyright">Copyright 2019 此游网版权所有</p>
    </div>
</div>
<script charset="utf-8" src="../../static/public/js/particles.js" type="text/javascript"></script>
<script charset="utf-8" src="../../static/admin/layui/layui.js" type="text/javascript"></script>

<script>
    layui.use(['form', 'layer'], function () {
        var form = layui.form;
        var $ = layui.jquery;
        //登录按钮事件
        form.on("submit(login)", function (data) {
            console.log('有毛病？')
            $.ajax({
                url: '/admin/login',
                type: 'post',
                dataType: 'json',
                contentType: 'application/json',
                data: JSON.stringify(data.field),
                success: function (resData) {
                    if (resData == 0) {
                        layer.msg('用户名或密码错误', {
                            icon: 0,
                            time: 1000
                        });
                    } else if (resData == 1) {
                        layer.msg('用户名或密码错误', {
                            icon: 1,
                            time: 1000
                        });
                        window.location.href = "index";

                    } else {
                        layer.msg('情况不对！', {
                            icon: 0,
                            time: 1000
                        });
                    }

                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert('系统错误，请联系管理员！');
                }
            });
            return false;
        });
        // 加载验证码
        /*  window.getCode = function(){
             $("#imgCode").attr("src","./login/getVerifyCode?"+Math.random());
          }*/
    })
</script>
</body>

</html>
